%percentage of converged experiments
function plotconv5(dir,m,prefs)
files=[2 2; 2 3; 2 5; 2 10; 3 2; 5 2; 10 2];
numfiles = length(files);
col=8;
data=[numfiles];
for i=1:numfiles
    alldata=load(strcat(dir,'\m',int2str(m),'_n',int2str(files(i,1)),'_d',int2str(files(i,2)),'_',prefs,'.run.results'));
    num=length(alldata);
    numblocks=alldata(num,3)+1;
    totruns=num/numblocks;
    for j=1:totruns
        data(i,j)=alldata(j*numblocks,col);
    end;
end;

errors=[0.01 0.001 0.0001 0.00001];
result=zeros(numfiles,length(errors));
for e=1:length(errors)
    for i=1:numfiles
        for j=1:totruns
            if (data(i,j)<=errors(e))
                result(i,e)=result(i,e)+1;
            end;
        end;
    end;
end;
result=result./totruns;




%a1 = x0:(x1-x0)/10:x1;


%for a1=.4
%g=1.5
lw=2;
fs=12;
set(gca,'FontSize',fs);
colors='ymcrgby';
legendstr=[];
x=1:numfiles;
for i=1:length(errors)
    plot(x,result(:,i),'Color',colors(i),'LineWidth', lw);
    legendstr=strvcat(legendstr,strcat('error=',num2str(errors(i))));
    hold on;
end;
legend(legendstr);
xlabel('Setting', 'FontSize', fs);
ylabel('percentage', 'FontSize', fs);
title('Percentage of all runs that converge to a given error after 5000 iterations');
hold off;


name = strcat('./conv5_m',int2str(m),'_',prefs);
print('-depsc',strcat(name, '.eps'));
%print('-dpdf',strcat(name, '.pdf'));
end

